package com.student.bean;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class FileIoStudent {
    public static void fileReadLinesStudent(ArrayList<Student> list) throws IOException {
        OperateStudent operateStudent = new OperateStudent();
        File file = new File("file\\Student.txt");
        List<String> strings = FileUtils.readLines(file, "UTF-8");
        String str1 = null, str2 = null, str3 = null;
        int j, x;
        for (int i = 0; i < strings.size(); i++) {
            for (j = 0; j < strings.get(i).length(); j++) {
                char charAt = strings.get(i).charAt(j);
                if (charAt == ' ') {
                    str1 = strings.get(i).substring(0, j);
                    break;
                }
            }
            for (x = j + 1; x < strings.get(i).length(); x++) {
                char charAt = strings.get(i).charAt(x);
                if (charAt == ' ') {
                    str2 = strings.get(i).substring(j + 1, x);
                    break;
                }
            }
            str3 = strings.get(i).substring(x + 1);

            char ch = str3.charAt(0);
            int num = (int) ch;
            int num2 = StringCharAt(num);
            ch = str3.charAt(1);
            num = (int) ch;
            int num3 = StringCharAt(num);
            int num4 = num2 * 10 + num3;
            Student student = new Student(str1, str2, num4);
            list.add(student);
        }
    }

    public static int StringCharAt(int i) {
        i = i - 48;
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
        return arr[i];
    }

    public static void fileWriteLinesStudent(ArrayList<Student> list) throws IOException {
        File file = new File("file\\Student.txt");
        FileUtils.writeLines(file, list);
    }

}


